﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class ZuanShi : MonoBehaviour {

	//钻石停留时间
	public float m_Time = 1.5f;
	GameObject player;
	float m_Y =0;
	GameManager game;
	void Start () {
		player = GameObject.FindGameObjectWithTag("Player");
		game = GameObject.FindGameObjectWithTag("GameObject").gameObject.GetComponent<GameManager>();
	}
	

	void Update () {
	
		m_Time-=Time.deltaTime;
		if(m_Time<=0&&player!=null)
		{
		  this.transform.position = Vector3.MoveTowards(this.transform.position,player.transform.position,0.2f);
		}else{
			m_Y = this.transform.position.y;
			this.transform.position = new Vector3(this.transform.position.x,m_Y-=Time.deltaTime*2,0);
		}
	}

	void OnTriggerEnter2D(Collider2D other)
	{
		if(other.tag.CompareTo("Player") == 0)
		{
            Instantiate(Resources.Load<GameObject>(SampleXml.prefabPath[15].ToString()));
			game.zuanshi_state();
			Destroy(this.gameObject);
		}else if(other.tag.CompareTo("Bounds") == 0)
		{
			//Destroy(this.gameObject);
		}
	}
}
